#include<fstream>
#include<string>
#include<iostream>
#include<vector>
#include<sstream>
#include<stdio.h>
#include "cplus.h"
using namespace std;



 //数据类型转换模板函数
 template <class Type>
 Type stringToNum(const string str)
 {
        istringstream iss(str);
        Type num;
        iss >> num;
        return num;
 }

double* A::test(char* line1) {
//        ifstream is("./gpstest.txt");
        string line;
//        getline(is,line);
        //line = "$GPGGA,025620.00,2602.33721,N,11911.49176,E,2,04,1.63,13.5,M,9.9,M,,0000*5D";

        line = line1;


        //读取第一行 GGA格式  $GPGGA,025620.00,2602.33721,N,11911.49176,E,2,04,1.63,13.5,M,9.9,M,,0000*5D
        //GGA字段含义   语句ID,UTC时间，纬度，N/S，经度，E/W，GPS状态，卫星数量，精度因子，海拔 。。。
        vector<string> arr1;  //定义一个字符串容器
        int position = 0;
        do
        {
            string tmp_s;
            position = line.find(","); //找到逗号的位置
            tmp_s = line.substr(0,position); //截取需要的字符串
            line.erase(0,position+1); //将已读取的数据删去
            arr1.push_back(tmp_s);   //将字符串压入容器中
        }while(position != -1);

        static double ret[2];
        static double stdRet[2];

        double d1 = stringToNum<double>(arr1[4]);
        ret[0] = d1/100;
        int integer1 = int(ret[0]);
        float decimal1 = ret[0] - integer1;
        float stdDecimal1 = (decimal1/60)*100;
        float longtitude = integer1 + stdDecimal1;
        cout<<"经度：";
        printf("%lf\n",longtitude);
        stdRet[0] = longtitude;
        //此处不能使用cout，否则输出精度将受到影响

        double d0 = stringToNum<double>(arr1[2]);
        ret[1] = d0/100;

        int integer2 = int(ret[1]);
        float decimal2 = ret[1] - integer2;
        float stdDecimal2 = (decimal2/60)*100;
        float latitude = integer2 + stdDecimal2;
        stdRet[1] = latitude;

        cout<<"纬度：";
        printf("%lf\n",latitude);



        return stdRet;
}